package pile.customer.service.impl;

import pile.customer.entity.Information;
import pile.customer.entity.User;
import pile.customer.mapper.InformationMapper;
import pile.customer.params.frequentlyAskedQuestions.SentMessageDTO;
import pile.customer.service.IInformationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import pile.customer.entity.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import pile.customer.utils.WebUtils;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import pile.customer.entity.PageList;
import org.apache.commons.lang.StringUtils;
import java.util.Arrays;
import pile.customer.params.information.DeleDTO;
import pile.customer.params.information.ListDTO;
/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 郭天义
 * @since 2024-06-03
 */
@Service
public class InformationServiceImpl extends ServiceImpl<InformationMapper, Information> implements IInformationService {

    @Autowired
    private InformationMapper informationMapper;

   @Override
   public ResponseResult listPage(ListDTO listDTO) {

       IPage<Information> iPage = new Page(listDTO.getPage(), listDTO.getLimit());
       //根据最后一次发送信息倒序查询  客服信息互通
       IPage data = informationMapper.pageList(iPage, listDTO);
       PageList pageList = new PageList();
       pageList.setCount(data.getTotal());
       pageList.setLimit(data.getSize());
       pageList.setList(data.getRecords());
       pageList.setPage(data.getCurrent());
       pageList.setPages(data.getPages());
        return new ResponseResult(pageList);
   }



   @Override
   public ResponseResult add(Information information) {
        informationMapper.insert(information);
        return new ResponseResult(200,"新增成功");
   }

    /**
     * 根据开始时间 结束时间 openid 查询这个人发送消息的数量
     * @param sentMessageDTO
     * @return
     */
    @Override
    public Integer selectTodaySentMessage(SentMessageDTO sentMessageDTO) {
        return informationMapper.selectTodaySentMessage( sentMessageDTO);
    }

    @Override
    public ResponseResult userInformationList(ListDTO listDTO) {
        IPage<Information> iPage = new Page(listDTO.getPage(), listDTO.getLimit());
        //根据最后一次发送信息倒序查询  客服信息互通
        IPage data = informationMapper.pageList(iPage, listDTO);
        PageList pageList = new PageList();
        pageList.setCount(data.getTotal());
        pageList.setLimit(data.getSize());
        pageList.setList(data.getRecords());
        pageList.setPage(data.getCurrent());
        pageList.setPages(data.getPages());
        return new ResponseResult(pageList);
    }


}
